(function($) {
	$.fn.extend({
		jqpictools : function(options){
			 var defaults = {
		                txtAreaObj : '', //TextArea对象
		                containerObj : '', //表情框父对象
		                textareaid: 'text',//textarea元素的id
		                popName : '', //iframe弹出框名称,containerObj为父窗体时使用
		                top : 0, //相对偏移
		                left : 0 //相对偏移
		            };
		            
		            var options = $.extend(defaults, options);
		            var cpos=0;//光标位置，支持从光标处插入数据
		            var textareaid = options.textareaid;
		            
		            return this.each(function() {
		                var Obj = $(this);
		                var container = options.containerObj;
		                $(Obj).bind("click", function(e) {
		                    e.stopPropagation();
		                    var picHtml = '<div id="pic" class="face">';
		                    picHtml += '<div id="texttb"><a class="f_close" title="关闭" href="javascript:void(0);"></a></div>';
		                    picHtml += '<div id="facebox">';
		                    picHtml += '<div id="face_detail" class="facebox clearfix"><ul>';
		                    
//		                    picHtml += '<li><img title="" src="../images/publish/uppicbtn.jpg"  style="width:90px;height:90px;cursor:pointer; position:relative;"   /></li>';
		                    picHtml += '<li>';
		                    picHtml += '<img id="fileimage" src="../images/publish/uppicbtn.jpg"  style="width:90px;height:90px;cursor:pointer; position:relative;">';
		                    picHtml += '<form name="picForm" id="picForm" enctype="multipart/form-data" method="post">';
		                    picHtml += '<input name="picImage" id="picImage" type="file" class="fileup">';
		                    picHtml += '</form>';
		                    picHtml += '</img>';
		                    picHtml += '</li>';
		                    picHtml += '</ul></div>';
		                    picHtml += '</div><div class="arrow arrow_t"></div></div>';

		                    container.find('#pic').remove();
		                    container.append(picHtml);
		                    
		                    //关闭表情框
		                    container.find(".f_close").bind("click", function() {
		                        container.find("#pic").remove();
		                    });
		                    //处理js事件冒泡问题
		                    $('body').bind("click", function(e) {
		                        e.stopPropagation();
		                       // container.find('#pic').remove();
		                        $(this).unbind('click');
		                    });
		                    if(options.popName != '') {
		                        $(window.frames[options.popName].document).find('body').bind("click", function(e) {
		                            e.stopPropagation();
		                            container.find('#pic').remove();
		                        });
		                    }
		                    container.find('#pic').bind("click", function(e) {
		                        e.stopPropagation();
		                    });
		                    var offset = $(e.target).offset();
		                    offset.top += options.top;
		                    offset.left += options.left;
		                    container.find("#pic").css(offset).show();
		                    
		                    $("#picImage").bind('change',function(){
		                    	var ajax_option={
		                				url  : "/web/publishInfo/upImage",
		                				type : "post",
		                				dataType : "json", 
		                				success:function(data){
		                					console.log(data);
		                					if(data && data.path){
		                						$('#fileimage').attr("src",data.path);
		                						$("#imagePath").val(data.path);
		                					}
		                				}
		                		};
		                    	$("#picForm").ajaxSubmit(ajax_option);
		                    });
		                    
		                });
		            });
		}
		
	});
	
	
})(jQuery);